package orm

import (
	"strings"
	"errors"
)

const (
	ExprSep = " "
)

type condValue struct {
	Operator string  //操作符
	conj string
	ColumnName string
	ExpectValue []interface{}
	isNot string
}

type Condition struct {
	Conds []condValue
}

func (cond *Condition)And(expr string,err *error ,args...interface{})(*Condition){
	Expr := strings.Split(expr,ExprSep)
	if len(Expr)!=2 {
		errNew := errors.New("Expr err:"+expr)
		err = &errNew
		return cond
	}

	cond.Conds = append(cond.Conds,condValue{Operator:Expr[1],conj:" AND ",ColumnName:Expr[0],ExpectValue:args,isNot:""})
	return cond
}

func (cond *Condition)AndNot(expr string,err *error ,args...interface{})(*Condition){
	Expr := strings.Split(expr,ExprSep)
	if len(Expr)!=2 {
		errNew := errors.New("Expr err:"+expr)
		err = &errNew
		return cond
	}

	cond.Conds = append(cond.Conds,condValue{Operator:Expr[1],conj:" AND ",ColumnName:Expr[0],ExpectValue:args,isNot:" NOT "})
	return cond
}
